package OptimalAlgorithm.Simulation;
//https://leetcode.cn/problems/count-and-say/
public class CountAndSay {
    public String countAndSay(int n) {
        String ret = "1";
        for (int i = 1; i < n; i++) {//用来计算第n个countAndSay
            StringBuilder str = new StringBuilder();
            for (int left = 0,right = 0; right < ret.length();) {
                while (right < ret.length() && ret.charAt(right) == ret.charAt(left)){
                    right++;
                }
                str.append(Integer.valueOf(right - left)).append(ret.charAt(left));
                left = right;
            }
            ret = String.valueOf(str);
        }
        return ret;
    }
}
